﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
using System.Windows.Shapes;

namespace ProfilerPDS {
    class LabelTS {

        private TextBlock _label;
        public TextBlock Label {
            get { return _label; }
        }

        private Rectangle _rect;
        public Rectangle Rect {
            get { return _rect; }
        }

        public LabelTS(Canvas drawAreaCanvas, string tooltip,EventType eventType, double fromLeft, double fromTop,Color color) {

            Brush brush = new SolidColorBrush(color);

            TextBlock txtL = new TextBlock();
            txtL.TextWrapping = TextWrapping.NoWrap;
            txtL.Foreground = brush;
            Rectangle rect = new Rectangle();
            rect.Stroke = brush;
            rect.StrokeThickness = 1;

            switch (eventType) {

                case EventType.New_Thread:
                    txtL.Text = "NT";
                    rect.ToolTip = "New Thread "+tooltip;
                    txtL.ToolTip = "New Thread " + tooltip;
                    break;
                case EventType.Destroy_Thread:
                    txtL.Text = "DT";
                    rect.ToolTip = "Destroy Thread " + tooltip;
                    txtL.ToolTip = "Destroy Thread " + tooltip;
                    break;
                case EventType.Enter_Function:
                    txtL.Text = "EF";
                    rect.ToolTip = "Enter Function " + tooltip;
                    txtL.ToolTip = "Enter Function " + tooltip;
                    break;
                case EventType.Leave_Function:
                    txtL.Text = "LF";
                    rect.ToolTip = "Leave Function " + tooltip;
                    txtL.ToolTip = "Leave Function " + tooltip;
                    break;
                case EventType.Exception_Thrown:
                    txtL.Text = "ET";
                    rect.ToolTip = "Exception Thrown " + tooltip;
                    txtL.ToolTip = "Exception Thrown " + tooltip;
                    break;
                case EventType.Exception_Catcher_Enter:
                    txtL.Text = "ECE";
                    rect.ToolTip = "Exception Catcher Enter " + tooltip;
                    txtL.ToolTip = "Exception Catcher Enter " + tooltip;
                    break;
                case EventType.Exception_Catcher_Leave:
                    txtL.Text = "ECL";
                    rect.ToolTip = "Exception Catcher Leave " + tooltip;
                    txtL.ToolTip = "Exception Catcher Leave " + tooltip;
                    break;
                case EventType.Shutdown:
                    txtL.Text = "SD";
                    rect.ToolTip = "Shutdown";
                    txtL.ToolTip = "Shutdown";
                    break;
                case EventType.ObjectCreated:
                    txtL.Text = "NV";
                    rect.ToolTip = "New Variable";
                    txtL.ToolTip = "New Variable";
                    break;
                default:
                    break;
            }
            txtL.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Canvas.SetLeft(txtL, fromLeft + 4);
            Canvas.SetTop(txtL, fromTop + 4);
            rect.Height = txtL.DesiredSize.Height + 8;
            rect.Width = txtL.DesiredSize.Width+8;
            Canvas.SetLeft(rect, fromLeft);
            Canvas.SetTop(rect, fromTop);
            drawAreaCanvas.Children.Add(rect);
            drawAreaCanvas.Children.Add(txtL);
            _label = txtL;
            _rect = rect;

        }
    }
}
